const util= require('../../utils/util.js');
const config=require('../../utils/config.js');
Page({
  data: {
    showView: false,
  },
  //事件处理函数
  addnav: function () {
    wx.navigateTo({
      url: '/pages/additem/additem',
    })
  }, 
  edit:function(e){
    let index=e.currentTarget.dataset.index;
    let data=this.data.res_list[index];
    wx.setStorageSync('edit_item', data);
    wx.navigateTo({
      url: '/pages/additem/additem?edit=1',
    })
  },
  click: function () {
    var that = this;
    wx.scanCode({
      success: (res) => {
        //console.log(res)
        var rt = res;
        wx.showModal({
          title: '提示？',
          content: '是否确定借/收此物品',
          confirmText: "借/收",
          cancelText: "取消",
          success: function (res) {
            //console.log(res);
            if (res.confirm) {
              //console.log(rt.result)
              wx.showLoading({
                title: '加载中',
              })
              //console.log(rt.result)
              wx.request({
                url: getApp().globalData.serverip + '/bid?itemid=' + rt.result,
                method: 'POST',
                header: {
                  'content-type': 'application/json', // 默认值
                  'sessionid': wx.getStorageSync("sessionid")
                },
                success: function (res) {
                  wx.hideLoading()
                  //console.log(JSON.stringify(res))
                }
              })

            } else {
              console.log('用户点击取消')
            }
          }
        });

      }
    })
  },
  bindViewTap: function() {
    
  },
  showorhide:function(){
    var that = this;
    that.setData({
      showView: (!that.data.showView)
    })
  },
  onLoad: function (options) {
    let url = '/app/b_res_list';
    // let url ='/app/res_link_list';
    let data = {
      open_id: wx.getStorageSync('open_id')
    };
    util.show_loading();
    util.request(url, data, res => {
      util.hide_loading();
      console.log(url, res)
      if (res) {
        this.setData({
          res_list: res.rows,
          root_url: config.root_url,
        })
      }
    })
  },
  onShow:function(){
  },
  show_qr_code:function(e){
    let res_id=e.currentTarget.dataset.res_id;
    console.log(res_id);
    let arr=[];
    arr.push(config.root_url + '/static/qrcode/' + res_id + '.png');
    wx.previewImage({
      urls: arr,
    })
  }
})
